(function(angular) {
  var AppController = function($scope, Item) {
    Item.query(function(response) {
      $scope.items = response ? response : [];
    });
    
    $scope.addItem = function(description) {
      new Item({
        description: description,
        checked: false
      }).$save(function(item) {
        $scope.items.push(item);
      });
      $scope.newItem = "";
    };
    
    $scope.updateItem = function(item) {
      item.$update();
      $scope.showEdit = true;
    };
    
    $scope.deleteItem = function(item) {
    	console.log(item.id);
//    	$.teninedialog({
//            title:'系统提示',
//            content:'确认删除本条记录?'
//        });
//    	alert("delete");
    	if(window.confirm('你确认要删除吗？')){
            //alert("确定");
    		item.$remove(function() {
    			$scope.items.splice($scope.items.indexOf(item), 1);
    		});
            return true;
         }else{
            //alert("取消");
            return false;
        }
    };
    
    $scope.btnEdit = function() {
    	$scope.showEdit = false;
    };
    
    $scope.btnCancel = function() {
    	$scope.showEdit = true;
    };
    
    // 默认不显示修改按钮，绑定ng-show
    $scope.showEdit = true;
  };
  
  AppController.$inject = ['$scope', 'Item'];
  angular.module("myApp.controllers").controller("AppController", AppController);
  
  
  /* my test */
  var TestController = function($scope) {
	  $scope.getCurrentSecond = function() {
		  $scope.x = new Date().getSeconds();
	  };
  };
  TestController.$inject = ['$scope'];
  angular.module("myApp.controllers").controller("TestController", TestController);
  
  
}(angular));